package com.ruoyi.schoolSys.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.schoolSys.domain.Student;
import com.ruoyi.schoolSys.mapper.StudentMapper;
import com.ruoyi.schoolSys.model.vo.AskLeaveVo;
import com.ruoyi.schoolSys.model.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.schoolSys.mapper.AskLeaveMapper;
import com.ruoyi.schoolSys.domain.AskLeave;
import com.ruoyi.schoolSys.service.IAskLeaveService;

/**
 * 请假管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-19
 */
@Service
public class AskLeaveServiceImpl implements IAskLeaveService 
{
    @Autowired
    private AskLeaveMapper askLeaveMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询请假管理
     * 
     * @param id 请假管理主键
     * @return 请假管理
     */
    @Override
    public AskLeaveVo selectAskLeaveById(Long id)
    {
        return askLeaveMapper.selectAskLeaveById(id);
    }

    /**
     * 查询请假管理列表
     * 
     * @param askLeave 请假管理
     * @return 请假管理
     */
    @Override
    public List<AskLeaveVo> selectAskLeaveList(AskLeave askLeave)
    {
        return askLeaveMapper.selectAskLeaveList(askLeave);
    }

    /**
     * 新增请假管理
     * 
     * @param askLeave 请假管理
     * @return 结果
     */
    @Override
    public int insertAskLeave(AskLeave askLeave)
    {
        askLeave.setCreateTime(DateUtils.getNowDate());
        askLeave.setApplyTime(DateUtils.getNowDate());
        askLeave.setProposerId(SecurityUtils.getUserId());
        Student student = new Student();
        student.setPatriarchId(askLeave.getProposerId());
        List<StudentVo> studentVos = studentMapper.selectStudentList(student);
        if(studentVos.size()>0){
            askLeave.setStudentId(studentVos.get(0).getId());
        }
        return askLeaveMapper.insertAskLeave(askLeave);
    }

    /**
     * 修改请假管理
     * 
     * @param askLeave 请假管理
     * @return 结果
     */
    @Override
    public int updateAskLeave(AskLeave askLeave)
    {
        askLeave.setUpdateTime(DateUtils.getNowDate());
        askLeave.setApproveTime(DateUtils.getNowDate());
        return askLeaveMapper.updateAskLeave(askLeave);
    }

    /**
     * 批量删除请假管理
     * 
     * @param ids 需要删除的请假管理主键
     * @return 结果
     */
    @Override
    public int deleteAskLeaveByIds(Long[] ids)
    {
        return askLeaveMapper.deleteAskLeaveByIds(ids);
    }

    /**
     * 删除请假管理信息
     * 
     * @param id 请假管理主键
     * @return 结果
     */
    @Override
    public int deleteAskLeaveById(Long id)
    {
        return askLeaveMapper.deleteAskLeaveById(id);
    }
}
